import  pymysql
from  bilibili_update import get_tag,get_tag_id_from_mysql
from  mysql_conf import mysel_conf
import time
conn = mysel_conf.pool()
cursor = conn.cursor()
import requests
import io
from PIL import Image
def get_content_ext_id():
    sql="SELECT id,pic_link FROM contents_ext  where  width =0  order by id desc "
    cursor.execute(sql)
    res=cursor.fetchall()
    return res
def main():
    for i in get_content_ext_id():
        try:
            file=io.BytesIO()
            print(i)
            file.write(requests.get(i['pic_link']).content)
            img=Image.open(file)
            print(img.size)

            sql = "UPDATE contents_ext SET width=%s, height=%s WHERE id=%s"
            cursor.execute(sql,(img.size[0],img.size[1],i['id']))
            conn.commit()
            file.close()
        except:
            pass


if __name__ == '__main__':
    main()